package cn.always.xiajia.admin.sys.controller.pc;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.always.xiajia.admin.client.api.sys.SysUserClient;
import cn.always.xiajia.admin.sys.entity.SysUser;
import cn.always.xiajia.admin.sys.service.SysUserService;
import cn.always.xiajia.framework.common.entity.AjaxResult;
import cn.always.xiajia.framework.common.entity.AjaxResultExt;
import cn.always.xiajia.framework.mybatis.core.controller.BaseControllerX;
import cn.always.xiajia.framework.mybatis.core.query.QueryWrapperX;
import cn.always.xiajia.framework.security.core.util.SecurityFrameworkUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "管理后台-用户中心")
@RestController
@RequestMapping("/admin/sys/sysuser")
@Validated
@Slf4j
public class SysUserController extends BaseControllerX {

	@Resource
	protected SysUserClient sysUserApi;

	@Resource
	protected SysUserService sysUserService;

	@PostMapping("/list")
	// @PreAuthorize("@ss.hasPermission('admin:sys:sysuser:list')")
	@Operation(summary = "列表")
	public AjaxResult list() {
		return sysUserApi.list();
	}

	@PostMapping("/list2")
	@PreAuthorize("@ss.hasPermission('admin:sys:sysuser:list')")
	@Operation(summary = "列表")
	public AjaxResult list2() {
		Long id = SecurityFrameworkUtils.getLoginUserId();

		Page<SysUser> page = buildPage(SysUser.class);
		Map<String, Object> map = buildParams();
		List<Integer> list = new ArrayList<>();
		list.add(1);
		list.add(2);
		String[] strings = new String[] { "2" };
		map.put("IN_userId && EQ_userCode || LE_createTime", new Object[] { strings, "admin1", "2024-01-11" });
		// map.put("EQ_userCode", "admin");
		// map.put("LE_createTime", "2024-01-11");
		QueryWrapperX<SysUser> queryWrapperX = new QueryWrapperX<>();
		queryWrapperX.buildByMap(map);
		// LambdaQueryWrapperX<SysUser> lambdaQueryWrapperx = new
		// LambdaQueryWrapperX<>();
		// lambdaQueryWrapperx.eq(SysUser::getUserId, 1);
		// lambdaQueryWrapperx.buildByMap(map);
		// QueryWrapper<SysUser> lambdaQueryWrapperxx = new QueryWrapper<>();
		// lambdaQueryWrapperxx.eq("user_id", 1);
		page = sysUserService.page(page, queryWrapperX);
		return AjaxResultExt.success(page, true);
	}
}
